<?php

require_once("main.php");


require_once(DIR_LIB."VsCore".DIR_SEP."vsupload.php");
require_once(DIR_LIB."VsGallery".DIR_SEP."vsgallery_factory.php");

$submited = FALSE;

// Page Image Selection Form Processing
//================================================================================================
$formType = isset($_POST['type']) ? $_POST['type'] : '';
$source = isset($_POST['source']) ? $_POST['source'] : '';
$file = '';

if((!empty($formType)) && (!empty($source))) {
	if($formType=='P') {	// Product Images
		if($source=='L') {
			$upload = new VsUpload($_FILES['userfile']);
			$upload->upload();

			$file = $upload->file();
			$submited = TRUE;
		}
	}
	else if($formType=='G') {	// Gallery Images
		if($source=='L') {
			$upload = new VsUpload($_FILES['userfile'], DIR_WWW."gallery_images".DIR_SEP);
			$upload->upload();

			$file = $upload->file();
			$submited = TRUE;

			if(!empty($file)) {
				$gi = new VsGalleryImage($file);
				$gi->save();
			}
		}
	}
}


// Page Image Selection
//================================================================================================
require_once("templates/XCart/xcart_imageselect.php");

//$page = ScbPageProductEdit::Instance();
$page = new XCartImageSelect($file, $submited);
//$page->setTitle("Product Edit Form");
echo $page->show();


?>
